<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>Spring4.2新特性之Import | Hui</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="Spring 4.2新特性之-@Import在spring4.2中加入了一个新特性 @import 作用注入类
4.2之前的解决方式：
123456789@Compentpublic class DemoService&amp;#123;    @Bean    public DemoDao demoDaoInject()&amp;#123;        return new DemoDao();    &amp;#">
<meta property="og:type" content="article">
<meta property="og:title" content="Spring4.2新特性之Import">
<meta property="og:url" content="http://mhuihui.oschina.io/m-pages/2017/01/04/Spring 4.2新特性之-@Import/index.html">
<meta property="og:site_name" content="Hui">
<meta property="og:description" content="Spring 4.2新特性之-@Import在spring4.2中加入了一个新特性 @import 作用注入类
4.2之前的解决方式：
123456789@Compentpublic class DemoService&amp;#123;    @Bean    public DemoDao demoDaoInject()&amp;#123;        return new DemoDao();    &amp;#">
<meta property="og:updated_time" content="2017-02-10T03:36:00.244Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Spring4.2新特性之Import">
<meta name="twitter:description" content="Spring 4.2新特性之-@Import在spring4.2中加入了一个新特性 @import 作用注入类
4.2之前的解决方式：
123456789@Compentpublic class DemoService&amp;#123;    @Bean    public DemoDao demoDaoInject()&amp;#123;        return new DemoDao();    &amp;#">
  
    <link rel="alternate" href="/atom.xml" title="Hui" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link rel="stylesheet" href="/m-pages/css/style.css">
  

</head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/m-pages/" id="logo">Hui</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/m-pages/">Home</a>
        
          <a class="main-nav-link" href="/m-pages/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" results="0" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://mhuihui.oschina.io/m-pages"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-Spring 4.2新特性之-@Import" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/m-pages/2017/01/04/Spring 4.2新特性之-@Import/" class="article-date">
  <time datetime="2017-01-04T12:11:38.000Z" itemprop="datePublished">2017-01-04</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      Spring4.2新特性之Import
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <hr>
<h2 id="Spring-4-2新特性之-Import"><a href="#Spring-4-2新特性之-Import" class="headerlink" title="Spring 4.2新特性之-@Import"></a>Spring 4.2新特性之-@Import</h2><p>在spring4.2中加入了一个新特性 @import 作用注入类</p>
<p>4.2之前的解决方式：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line"><span class="meta">@Compent</span></div><div class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">DemoService</span></span>&#123;</div><div class="line">    <span class="meta">@Bean</span></div><div class="line">    <span class="function"><span class="keyword">public</span> DemoDao <span class="title">demoDaoInject</span><span class="params">()</span></span>&#123;</div><div class="line">        <span class="keyword">return</span> <span class="keyword">new</span> DemoDao();</div><div class="line">    &#125;</div><div class="line">    </div><div class="line">    </div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>4.2 之后就可以这样去实现了：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line"><span class="meta">@Compent</span></div><div class="line"><span class="meta">@Import</span>(DemoDao.class)</div><div class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">DemoService</span></span>&#123;</div><div class="line"></div><div class="line">&#125;</div></pre></td></tr></table></figure>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://mhuihui.oschina.io/m-pages/m-pages/2017/01/04/Spring 4.2新特性之-@Import/" data-id="ciyzazarx000es8vgol2l0eys" class="article-share-link">Share</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/m-pages/tags/编程/">编程</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/m-pages/2017/01/05/SSH 集群配置/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          SSH 集群配置
        
      </div>
    </a>
  
  
    <a href="/m-pages/2016/12/09/JPA 高级部分/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">JPA高级学习</div>
    </a>
  
</nav>

  
</article>

</section>
        
          <aside id="sidebar">
  
    

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/m-pages/tags/ide/">ide</a></li><li class="tag-list-item"><a class="tag-list-link" href="/m-pages/tags/linux/">linux</a></li><li class="tag-list-item"><a class="tag-list-link" href="/m-pages/tags/编程/">编程</a></li><li class="tag-list-item"><a class="tag-list-link" href="/m-pages/tags/设计/">设计</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/m-pages/tags/ide/" style="font-size: 13.33px;">ide</a> <a href="/m-pages/tags/linux/" style="font-size: 16.67px;">linux</a> <a href="/m-pages/tags/编程/" style="font-size: 20px;">编程</a> <a href="/m-pages/tags/设计/" style="font-size: 10px;">设计</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/m-pages/archives/2017/02/">February 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/m-pages/archives/2017/01/">January 2017</a></li><li class="archive-list-item"><a class="archive-list-link" href="/m-pages/archives/2016/12/">December 2016</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/m-pages/2017/02/10/go语言学习笔记（四)/">go语言学习笔记（四）</a>
          </li>
        
          <li>
            <a href="/m-pages/2017/02/10/hello-world/">Hello World</a>
          </li>
        
          <li>
            <a href="/m-pages/2017/01/14/go语言学习笔记（三）/">go语言学习笔记（三）</a>
          </li>
        
          <li>
            <a href="/m-pages/2017/01/13/go语言学习笔记（二）/">go语言学习笔记（二）结构体和切片</a>
          </li>
        
          <li>
            <a href="/m-pages/2017/01/12/go语言学习笔记（一）/">go语言开发环境搭建</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2017 hui<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/m-pages/" class="mobile-nav-link">Home</a>
  
    <a href="/m-pages/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  <link rel="stylesheet" href="/m-pages/fancybox/jquery.fancybox.css">
  <script src="/m-pages/fancybox/jquery.fancybox.pack.js"></script>


<script src="/m-pages/js/script.js"></script>

  </div>
</body>
</html>